/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.upms.params;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mt.roll.core.enums.SexEnum;
import com.mt.roll.core.base.BaseParam;
import com.mt.roll.core.validator.constraints.Enum;
import com.mt.roll.core.validator.constraints.Password;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDate;

/**
 * <p>
 * 系统用户
 * </p>
 *
 * @author jiff
 * @date 2018/11/9
 * @since 1.0
 */
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@Data
@Builder
@ApiModel(value = "系统用户", description = "用于新增和更新用户信息")
public class SysUserParam extends BaseParam {


    /**
     * 主键，自增
     */
    @ApiModelProperty(value = "主键，更新时需要填写", example = "1")
    @NotNull(message = "用户ID不能为空", groups = {UpdateGroup.class})
    private Long id;

    /**
     * 组织ID
     */
    @ApiModelProperty(value = "组织ID", required = true, example = "1")
    @NotNull(message = "组织ID不能为空")
    private Long orgId;

    /**
     * 系统用户手机号
     */
    @ApiModelProperty(value = "手机号", required = true, example = "13588441519", position = 1)
    @NotBlank(message = "手机号码不能为空", groups = {AddGroup.class})
    @Pattern(regexp = "^1[3456789]\\d{9}$", message = "手机号码格式不正确", groups = {AddGroup.class})
    private String mobile;

    /**
     * 密码
     */
    @ApiModelProperty(value = "密码，新增时需要填写", required = true, example = "123abc.", position = 2)
    @Length(min = 6, max = 20, message = "密码长度为6-20位", groups = {AddGroup.class})
    @Password(format = Password.PasswordFormat.NUMBER_LETTER_CHAR, message = "密码必须同时包含数字、字母、特殊字符")
    private String password;

    /**
     * 工号
     */
    @ApiModelProperty(value = "工号", example = "10000", position = 3)
    private String code;

    /**
     * 姓名
     */
    @ApiModelProperty(value = "姓名", required = true, example = "jiff", position = 3)
    @NotBlank(message = "{lis.validator.constraints.NotBlank.name.message}")
    private String name;

    /**
     * 生日
     */
    @ApiModelProperty(value = "生日", example = "2018-11-11")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate birthday;

    /**
     * 系统用户邮箱
     */
    @ApiModelProperty(value = "邮箱", example = "jiff@ulabcare.com")
    @Email
    private String email;

    /**
     * 性别（1女，2男）
     */
    @ApiModelProperty(value = "性别（1女，2男）", example = "1")
    @Enum(message = "{lis.validator.constraints.SexEnum.message}", target = {SexEnum.class})
    private Integer sex;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注", position = Integer.MAX_VALUE)
    private String remark;

}
